﻿using System;
using Csla;
using Ent.AccesoDatos;

namespace Ent.Inscripcion.Core
{
    [Serializable]
    public class VerificarOfertaCmd : CommandBase<VerificarOfertaCmd>
    {
        #region Factory Methods

        public static VerificarOfertaCmd Execute(string horario)
        {
            var cmd = new VerificarOfertaCmd();
            cmd.BeforeServer();
            cmd = DataPortal.Execute<VerificarOfertaCmd>(cmd);
            cmd.AfterServer();
            return cmd;
        }

        public VerificarOfertaCmd()
        {
        }

        #endregion

        #region Client-side Code

        // TODO: add your own fields and properties
        bool _result;

        public bool Result
        {
            get { return _result; }
        }

        private void BeforeServer()
        {
            // TODO: implement code to run on client
            // before server is called
        }

        private void AfterServer()
        {
            // TODO: implement code to run on client
            // after server is called
        }

        #endregion

        #region Server-side Code

        protected override void DataPortal_Execute()
        {
            var accesoDatos = new DriveDataBase(TypeDataBase.Mysql);
            
            var datos = accesoDatos.EjecutarScalar("VerificaOferta", null);
            int resultado;
            int.TryParse(datos.ToString(), out resultado);
            _result = resultado != 0;
        }

        #endregion
    }
}
